import 'package:enjoy_three/pages/house/components/house_list.dart';
import 'package:enjoy_three/pages/house/location_list.dart';
import 'package:enjoy_three/pages/login/index.dart';
import 'package:enjoy_three/pages/notice/index.dart';
import 'package:enjoy_three/pages/profile/index.dart';
import 'package:enjoy_three/pages/tab_bar_page.dart';
import 'package:enjoy_three/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(
    MaterialApp(
      routes: {
        '/': (context) => const TabBarPage(),
        '/detail': (context) => const NoticeDetail(),
      },
      onGenerateRoute: (settings) {
        final tokenManager = TokenManager();
        final token = tokenManager.getToken() ?? '';
        if (token.isEmpty && settings.name != '/login') {
          return MaterialPageRoute(builder: (context) => const LoginPage());
        }

        if (settings.name == '/profile') {
          return MaterialPageRoute(
            builder:
                (context) => ProfilePage(userInfo: settings.arguments as Map),
          );
        }
        if (settings.name == '/house_list') {
          return MaterialPageRoute(builder: (context) => const HouseList());
        }
        if (settings.name == '/location_list') {
          return MaterialPageRoute(builder: (context) => const LocationList());
        }
      },
      initialRoute: '/',
    ),
  );
}
